package com.bestcem.xm.user.service.impl;

import com.bestcem.xm.common.core.domain.web.ServiceResult;
import com.bestcem.xm.user.dao.UserMfaRoleDao;
import com.bestcem.xm.user.service.UserMfaRoleService;
import com.bestcem.xm.user.service.dto.user.UserMfaRoleDTO;
import com.bestcem.xm.user.util.convert.UserMfaRoleConvert;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 用户登录安全验证关联角色相关服务
 *
 * @author panyun <yun.pan@idiaoyan.com>
 * @version v1.0
 * @date 2022/6/13 10:31
 */
@Slf4j
@Service
public class UserMfaRoleServiceImpl implements UserMfaRoleService {
    @Resource
    private UserMfaRoleConvert userMfaRoleConvert;

    @Resource
    private UserMfaRoleDao userMfaRoleDao;

    @Override
    public ServiceResult<List<UserMfaRoleDTO>> listMfaRoleByCondition(UserMfaRoleDTO userMfaRole) {
        return ServiceResult.success(userMfaRoleConvert.dos2Dtos(userMfaRoleDao.listByCondition(userMfaRoleConvert.dto2Do(userMfaRole))));
    }

    @Override
    public ServiceResult<Integer> insertSelective(UserMfaRoleDTO userMfaRoleDTO) {
        return ServiceResult.success(userMfaRoleDao.insertSelective(userMfaRoleConvert.dto2Do(userMfaRoleDTO)));
    }

    @Override
    public ServiceResult<Integer> deleteByRoleIds(String orgId, List<String> deleteRoleIds) {
        if (CollectionUtils.isEmpty(deleteRoleIds)) {
            return ServiceResult.fail("deleteRoleIds为空");
        }
        return ServiceResult.success(userMfaRoleDao.deleteByRoleIds(orgId, deleteRoleIds));
    }
}
